package com.one.servlet;

import com.one.dao.impl.userDaoImpl;
import com.one.pojo.User;
import com.one.service.impl.userServiceImpl;
import com.one.service.userService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author LJ
 * @create 2022-04-24-15:19
 */
@WebServlet("/register1")
public class registerServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("name");
        String password = req.getParameter("password");
        req.getParameter("name");
        System.out.println("go"+name);
        System.out.println("go"+password);
        User user=new User();
        user.setName(name);
        user.setPassword(password);
        userService userservice=new userServiceImpl();
        int i = userservice.userRegister(user);
        if (i>0){
            HttpSession session = req.getSession();
            session.setAttribute("name", user.getName());
            session.setAttribute("id",user.getId());
            req.getRequestDispatcher("index").forward(req, resp);
        }else {
            req.setAttribute("state", "注册失败");
            req.getRequestDispatcher("index").forward(req, resp);
        }
    }
}

